#include "VertibrateObject.h"
#include "SkeletonReader.h"

VertibrateObject::VertibrateObject( TextureManager * textureManager,
					  Vector2D position,
					  Vector2D * vertices,
					  int numVertices,
					  float mass,
				      bool isGrabbable,
				      char * skeletonFile)
: Object(textureManager, position, vertices, numVertices, mass, isGrabbable)
{
	this->textureManager = textureManager;
	skeleton = NULL;
	if(skeletonFile)
	{
		skeleton = new Skeleton(textureManager, skeletonFile);
		skeleton->SetAnimation("walk", 0,0,1);
	}
}
				      
VertibrateObject::~VertibrateObject()
{
	if(skeleton)
	{
		delete(skeleton);
		skeleton = NULL;
	}
}
bool VertibrateObject::VertibrateObjectPreDrawEntryPoint()
{
	return false;
}
bool VertibrateObject::PreDrawEntryPoint()
{
	if(VertibrateObjectPreDrawEntryPoint())
	{
		return true;
	}
	
	if(skeleton)
	{	
		Vector2D drawPosition = position + (vertices[0] + vertices[1]) * 0.5;
		skeleton->Draw(drawPosition);
	}
	return true;
}
bool VertibrateObject::VertibrateObjectPreThinkEntryPoint(double elapsedTime)
{
	return false;
}
bool VertibrateObject::PreThinkEntryPoint(double elapsedTime)
{
	if(VertibrateObjectPreThinkEntryPoint(elapsedTime))
	{
		return true;
	}
	if(skeleton)
	{
		
		skeleton->Think(elapsedTime);
	}
	return false;
}
bool VertibrateObject::PreRotate(float rotation)
{
	if(skeleton)
	{
		skeleton->RadianRotate(rotation);
	}
	return false;
}
